package system;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import bean.MediaBean;
import bean.MediaType;

/**
 * Class that implements a Sound
 * @author Otavio Lima, Laura Dutra
 *
 */
public class Sound extends Media {

	private static String mediaId = "sou";
	
	/**
	 * Constructor
	 * @param id - id of sound
	 * @param url - data of sound
	 * @param description - description of sound
	 * @param owner - owner of the sound
	 */
	public Sound(String id, String url, String description, String owner) {
		super(id, url, description, MediaType.SOUND, owner);
	}
	
	/**
	 * Returns a list of medias of post passed as parameter
	 * @param postId
	 * @return list of media
	 */
	public static List<Media> getSoundByPost(String postId){


		List<Media> mediasByPost = new ArrayList<Media>();
		List<MediaBean> list = mediaDao.list();
		MediaBean media;
		for(Iterator<MediaBean> it = list.iterator(); it.hasNext();){
			media = it.next();
			if(media.getId().contains(postId)){
				if(media.getId().contains(mediaId))
					mediasByPost.add(new Sound(media.getId(), media.getURL(), media.getDescription(), media.getOwner()));

			}

		}
		return mediasByPost;
	}
}	

